<?php
function locateBin($bin) {
    foreach (array('/usr/local/bin','/usr/bin','/bin','/usr/sbin') as $dir) {
        if (file_exists($dir.'/'.$bin)) {
            return $dir.'/'.$bin;
        }
    }
    return $bin;
}
error_reporting(E_ALL ^ E_NOTICE);
if ($_SERVER['argc']<2) {
    echo 'php ',$_SERVER['argv'][0],' LocalSettings.php',"\n";
    die();
}
$f = $_SERVER['argv'][1];
if (!file_exists($f)) {
    echo 'file ',$f," not exists\n";
    die();
}

define('MEDIAWIKI',1);
require_once($f);

mysql_connect($wgDBserver, $wgDBuser, $wgDBpassword);
mysql_select_db($wgDBname);

$sql = "SHOW TABLES LIKE '{$wgDBprefix}%'";
$result = mysql_query($sql);
$tables = array();
while ($row=mysql_fetch_array($result)) {
    $tables[] = $row[0];
}
system(locateBin('mysqldump').' -h'.$wgDBserver.' -u'.$wgDBuser.' -p'.$wgDBpassword.' '.$wgDBname.' '.implode(' ',$tables),$r);
